#include <stdlib.h>
#include <time.h>
#include <unistd.h>
#include "processbar.h"

#define FILE_SIZE (1024*1024*1024)

void download(callbact_t cb)
{
    srand(time(NULL)^1023);
    int total=FILE_SIZE;
    while(total)
    {
        usleep(10000);  //下载动作
        int once=rand()%(1024*1024*5);
        total-=once;
        if(total<0) 
            total=0;

        //求当前进度
        int download = FILE_SIZE - total;
        double rate = (download * 1.0 / FILE_SIZE) * 100.0;
        //printf("download: %lf\n", rate);
        cb(rate);
    }
    printf("\n");
}

int main()
{
    //process();
    download(process_flush);
    return 0;
}
